/*
 * @Author: jhw
 * @Date: 2025-08-14 14:34:01
 * @LastEditors: jhw
 * @LastEditTime: 2025-08-14 14:37:53
 * @Description:
 */
import axios from 'axios';
import { ElMessage } from 'element-plus';
const request = axios.create({
  timeout: 5000,
});

// 请求拦截器
request.interceptors.request.use(
  (config) => {
    console.log('======请求参数======:', config.url, config.data);

    return config;
  },
  (error) => {
    // 请求错误处理
    console.log('Request Error:', error);
    return Promise.reject(error);
  },
);

// 响应拦截器
request.interceptors.response.use(
  (response) => {
    console.log('======响应参数======:', response.config.url, response.data);

    // 响应后处理
    if (response.status === 200) {
      return Promise.resolve(response.data);
    } else {
      ElMessage.error(response.data);
      return Promise.reject(response.data);
    }
  },
  (error) => {
    return Promise.reject(error);
  },
);

export default request;
